
# https://blog.csdn.net/yisun123456/article/details/78318820

from pyspark import SparkConf, SparkContext
from pyspark.sql import SQLContext
from pyspark.sql.types import *

from Core.Config import *
uri = "mongodb://" + config.cfg["MongoDBAddress"] + ":27017"

# ---全部加载，较慢---
sc = SparkContext()
ctx = SQLContext(sc)
test_collection = ctx.read.format("com.mongodb.spark.sql").\
    options(uri=uri, database="Instruments", collection="Stock").\
    load()

test_collection.printSchema()
test_collection.first()